import {
  reqGetCompanyInfo
} from '../../utils/api.js'

import {
  getReqData,
} from '../../utils/util.js'

const app = getApp()

/**
 * 经度0~360，纬度-90~90
 */
Page({
  data: {
    title_url: '',
    latitude: 23.324111,
    longitude: 107.583211,
    markers: [{
      id: 1,
      latitude: 23.324111,
      longitude: 107.583211,
      name: '永昌装饰'
    }]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    const {
      BASE_IMG_URL
    } = app.globalData
    const {
      images_contact_us
    } = app.globalData.titleImagesDetailTwo[0]

    const {
      result
    } = await reqGetCompanyInfo()
    const data = getReqData(result)
    if (!data) return null
    const {
      phone,
      address
    } = data

    this.setData({
      title_url: BASE_IMG_URL + images_contact_us[0],
      phone,
      address
    })
  },
  onReady: function (e) {
    this.mapCtx = wx.createMapContext('myMap')
    this.mapCtx.moveToLocation()
  },
  getCenterLocation: function () {
    this.mapCtx.getCenterLocation({
      success: function (res) {
        console.log(res.longitude)
        console.log(res.latitude)
      }
    })
  },
  moveToLocation: function () {
    this.mapCtx.moveToLocation()
  },
  translateMarker: function () {
    this.mapCtx.translateMarker({
      markerId: 1,
      autoRotate: true,
      duration: 1000,
      destination: {
        latitude: 23.10229,
        longitude: 113.3345211,
      },
      animationEnd() {
        console.log('animation end')
      }
    })
  },
  includePoints: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.10229,
        longitude: 113.3345211,
      }, {
        latitude: 23.00229,
        longitude: 113.3345211,
      }]
    })
  }
})